Imports EntertainmentManager.GUIPopulator
Imports BusinessLogicLayer.BLException
Imports DataAccessLayer
Imports UniversalLayer.ULDataHandler

Friend NotInheritable Class frmSplash

    'TODO: This form can easily be set as the splash screen for the application by going to the "Application" tab
    '  of the Project Designer ("Properties" under the "Project" menu).

    ''' <summary>
    ''' Timer Duration
    ''' </summary>
    ''' <remarks></remarks>
    Private iTimerDuration As Integer
    ''' <summary>
    ''' Splash screen :: TRUE (Enable)
    ''' </summary>
    ''' <remarks></remarks>
    Friend bEnableSplash As Boolean = True
    ''' <summary>
    ''' Location of Splash image
    ''' </summary>
    ''' <remarks></remarks>
    Private sSplashImgLocation As String
    ''' <summary>
    ''' DataTable containing all settings
    ''' </summary>
    ''' <remarks></remarks>
    Private dtSettingsMain As DataTable

    Public Sub New(ByVal dtSettings As DataTable)
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        '        Dim oRandom As Random
        '        Dim iSplashImgIndex As String
        'Dim _DLSettings As DLSettings
        Try
            '            _DLSettings = New DLSettings(dtSettingsMain)
            '            oRandom = New Random(CInt(System.DateTime.Now.Ticks Mod System.Int32.MaxValue))
            '            iSplashImgIndex = CStr(oRandom.Next(0, 29))
            'sSplashImgLocation = Application.StartupPath & "\img\" & iSplashImage & ".splash"
            '            sSplashImgLocation = DLMain.CreatePosterPath(iSplashImgIndex, Application.StartupPath & "\img", DLMain.ePosterParent.Splash, "splash")
            'If Not BusinessLogicLayer.BLMain.IsFileExists(sSplashImgLocation) Then _
            '    sSplashImgLocation = DLMain.CreatePosterPath(True, DLMain.ePosterParent.Splash)
            CopyDataTable(dtSettings, dtSettingsMain)
            GUIPopulator.FetchRandomSplashImage(sSplashImgLocation, dtSettingsMain)

            tmrSplashRotator.Enabled = False
            bEnableSplash = CBool(DLSettings.FetchOneSetting(dtSettingsMain, "Splash", "Enabled"))
            tmrSplash.Interval = 500 'CInt(DLSettings.FetchOneSetting(dtSettingsMain, "Splash", "Interval"))
            tmrSplashRotator.Interval = CInt(DLSettings.FetchOneSetting(dtSettingsMain, "Splash", "RotationDuration"))
            iTimerDuration = CInt(DLSettings.FetchOneSetting(dtSettingsMain, "Splash", "Duration"))

            picSplash.InitialImage = Image.FromFile(DLMain.CreatePosterPath(Nothing, True, DLMain.ePosterParent.Splash))
            'picSplash.InitialImage = Image.FromFile(sSplashImgLocation)
        Finally
            '           oRandom = Nothing
            '           iSplashImgIndex = Nothing
            '           _DLSettings = Nothing
        End Try
    End Sub

    Private Sub frmSplash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Me.BackgroundImage = Image.FromFile(sSplashLocation)
        picSplash.ImageLocation = sSplashImgLocation
        picSplash.SizeMode = PictureBoxSizeMode.StretchImage

        'Display Login screen if Splash screen is disabled
        If Not bEnableSplash Then GUIPopulator.DisplayLoginScreen(Me) : Me.Close() ': Exit Sub

        'Set up the dialog text at runtime according to the application's assembly information.  

        'TODO: Customize the application's assembly information in the "Application" pane of the project 
        '  properties dialog (under the "Project" menu).

        'Application title
        If My.Application.Info.Title <> "" Then
            lblApplicationTitle.Text = My.Application.Info.Title
        Else
            'If the application title is missing, use the application name, without the extension
            lblApplicationTitle.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
        End If

        ''Format the version information using the text set into the Version control at design time as the
        ''  formatting string.  This allows for effective localization if desired.
        ''  Build and revision information could be included by using the following code and changing the 
        ''  Version control's designtime text to "Version {0}.{1:00}.{2}.{3}" or something similar.  See
        ''  String.Format() in Help for more information.
        '    lblVersion.Text = System.String.Format(lblVersion.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor, My.Application.Info.Version.Build, My.Application.Info.Version.Revision)
        lblVersion.Text = System.String.Format(lblVersion.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor, My.Application.Info.Version.Build, My.Application.Info.Version.Revision)
        lblCopyright.Text = My.Application.Info.Copyright 'Copyright info

        'Enable splash timer only after whole page info is loaded
        tmrSplash.Enabled = bEnableSplash
    End Sub

    Private Sub tmrSplash_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSplash.Tick
        Static iTimerTracker As Long = 0

        iTimerTracker += tmrSplash.Interval
        If iTimerTracker >= iTimerDuration Then
            tmrSplash.Enabled = False

            'Dim _GUIPopulator As EntertainmentManager.GUIPopulator
            Try
                '_GUIPopulator = New EntertainmentManager.GUIPopulator
                tmrSplashRotator.Enabled = True
                DisplayLoginScreen(Me)
            Catch ex As Exception
                ThrowBLException(ex, "EntertainmentManager.frmSplash.tmrSplash_Tick")
            Finally
                '_GUIPopulator = Nothing
                Me.Close()
                'frmLogin.ShowDialog()
            End Try
        End If
    End Sub

    Private Sub tmrSplashRotator_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSplashRotator.Tick
        picSplash.ImageLocation = GUIPopulator.FetchRandomSplashImage(sSplashImgLocation, dtSettingsMain)
    End Sub
End Class
